package com.itbuka.search.controller;

import com.itbuka.entity.Result;
import com.itbuka.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 商品搜索服务
 */
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private SearchService searchService;

    /**
     * 根据关键字查询
     */
    @PostMapping("/select")
    public Result search(@RequestBody Map<String, String> paramMap){
        try {
            Map search = searchService.search(paramMap);
            return new Result("查询成功",search);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}